package com.example.demo21_spring_session.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
public class HelloController {

    @Value("${server.port}")
    private Integer port;

    @GetMapping("/get")
    public String get(HttpSession session) {
        String name = (String) session.getAttribute("name");
        return name + ":" + port;
    }

    @GetMapping("/set")
    public String set(HttpSession session, HttpServletRequest request) {
        String name = request.getParameter("name");
        session.setAttribute("name", name);
        return "set " + name;
    }

}
